import useApp from "@/stores/app";
import Taro from "@tarojs/taro";

const checkLogin = async (url?: string, fn: any = Taro.navigateTo) => {
  if (!useApp().isLogined) {
    const { cancel } = await Taro.showModal({
      title: "该功能需要登录！",
      confirmText: "去登录",
    });

    if (cancel) return Promise.reject({ msg: "未登录，取消去登录" });

    url = "/pages/login/index";
  }

  if (url) {
    fn({ url });
    return Promise.reject();
  }
};

export default checkLogin;
